#include <bits/stdc++.h>
#define int long long
#define x first
#define y second

using namespace std;


const int N = 1e5 + 10;
int prefix[N];
int suffix[N];
pair<int, int> p[N];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i].y >> p[i].x;
	}
	sort(p+1, p+1+n); // 根据位置排序
	int prefix_cnt = 0;
	for (int i = 1; i <= n; i++) {
		prefix[i] = prefix[i - 1];
		prefix[i] += prefix_cnt*(p[i].x-p[i-1].x);
		prefix_cnt += p[i].y;
	}
	
	int suffix_cnt = 0;
	for (int i = n; i >= 1; i--) {
		suffix[i] = suffix[i + 1] ;
		suffix[i] += suffix_cnt*(p[i+1].x-p[i].x);
		suffix_cnt += p[i].y;
	}
	
	int ans = 1e18;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, prefix[i] + suffix[i]);
	}
	
	cout << ans << '\n';
	return 0;
}
